package com.ouken.com;

import com.gen.tool.SoundPlayer;
//import com.ouken.tool.MplayerTool;
import com.ouken.tool.MyApp;

import android.app.Activity;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

public class SettingActivity extends Activity {
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		SoundPlayer.pauseMusic();
	}
	private MyApp appState;
	private SharedPreferences userInfo;
	private ToggleButton tb_music;
	private ImageButton ib_back;

	private void initView(){
		userInfo = getSharedPreferences("user_info", 0);
		appState = ((MyApp)getApplicationContext());
		//appState.setMusic(userInfo.getString("MUSIC", "ON").equals("ON"));
		appState.addActivity(SettingActivity.this);
		appState = (MyApp)getApplicationContext();
        
	    tb_music = (ToggleButton)findViewById(R.id.settingActivity_tb_music);
	    tb_music.setChecked(SoundPlayer.isMusicSt());
        ib_back = (ImageButton)findViewById(R.id.settingActivity_ib_back);
		
	}
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		SoundPlayer.startMusic();
	}
	public void onCreate(Bundle savedInstanceState) {
		   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.setting);
        initView();
        
        
        tb_music.setOnCheckedChangeListener(new OnCheckedChangeListener(){

			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
				SoundPlayer.playSound(R.raw.keypress_common);
				tb_music.setChecked(arg1);
				/*appState.setMusic(arg1?true:false);
				userInfo.edit().putString("MUSIC", arg1?"ON":"OFF").commit();  */
				
				SoundPlayer.setSoundSt(arg1?true:false);
				SoundPlayer.setMusicSt(arg1?true:false);
				
			}
        	
        });
        
        
        ib_back.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				SoundPlayer.playSound(R.raw.keypress_common);
				// TODO Auto-generated method stub
				//mplayerTool.playButtonPressed(SettingActivity.this);
				SettingActivity.this.finish();
			}
		});
        
        
        
	}

}
